package com.songlanyun.modules.comment.controller.admin;

import java.util.Arrays;
import java.util.Map;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.comment.entity.OrderGoodsComment;
import com.songlanyun.modules.comment.service.OrderGoodsCommentService;
import com.songlanyun.modules.user.controller.AbstractController;
import com.songlanyun.pay.configure.WxPayConfig;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 订单商品评论
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-30 18:09:47
 */
@RestController
@RequestMapping("admin/comment/orderGoods")
public class OrderGoodsCommentAdminController extends AbstractController {
    @Autowired
    private OrderGoodsCommentService orderGoodsCommentService;

    /**
     * 平台、商家评论列表
     */
    @GetMapping("/list")
//    @RequiresPermissions("comment:orderGoodsComment:list")
    public R list(@RequestParam Map<String, Object> params) {

        setShopId(params);
        PageUtils page = orderGoodsCommentService.queryCommentPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
//    @RequiresPermissions("comment:orderGoodsComment:info")
    public R info(@PathVariable("id") Long id) {
        OrderGoodsComment orderGoodsComment = orderGoodsCommentService.getById(id);

        return R.ok().put("data", orderGoodsComment);
    }


    /**
     * 显示
     */
    @SysLog("订单商品评论是否显示")
    @PostMapping("/show")
//    @RequiresPermissions("comment:orderGoodsComment:info")
    public R show(@RequestBody OrderGoodsComment orderGoodsComment) {
        if (orderGoodsComment.getShow() == null) {
            throw new RRException("必传字段不能为空");
        }

        OrderGoodsComment comment = orderGoodsCommentService.getById(orderGoodsComment.getId(), true);
        comment.setShow(orderGoodsComment.getShow());
        orderGoodsCommentService.updateById(comment);

        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("订单商品评论删除")
    @DeleteMapping("/delete/{id}")
//    @RequiresPermissions("comment:orderGoodsComment:delete")
    public R delete(@PathVariable("id") Long id) {

        orderGoodsCommentService.removeById(id);

        return R.ok();
    }


}
